package com.xinqing.test.modle.algorithm;

import com.feidee.fdcommon.util.ToolUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author:CHQ
 * @Date:2020/9/29 17:06
 * @Description
 */
public class ForecastParam {
    /**
     * 业务ID
     */
    private String busId;
    /**
     * 算法ID
     */
    private String[] models;
    /**
     * 模型特征（有多物品特征时，此处作为公共特征）
     */
    private Map<String, Object> features;
    /**
     * 多物品特征
     * key：物品ID，value：物品特征
     */
    private Map<String, Map<String, Object>> multiFeatures;
    /**
     * 结果top
     */
    private int top;
    /**
     * 请求跟踪ID
     */
    private String traceId;
    /**
     * 拼装 {@link #features} 和 ${@link #multiFeatures} 的究极无敌 feature
     */
    private Map<String, Map<String, Object>> totalFeatures;

    public int getTop() {
        return top;
    }

    public void setTop(int top) {
        this.top = top;
    }

    public String getBusId() {
        return busId;
    }

    public void setBusId(String busId) {
        this.busId = busId;
    }

    public String[] getModels() {
        return models;
    }

    public void setModels(String[] models) {
        this.models = models;
    }

    public Map<String, Object> getFeatures() {
        return features;
    }

    public void setFeatures(Map<String, Object> features) {
        this.features = features;
    }

    public Map<String, Map<String, Object>> getMultiFeatures() {
        return multiFeatures;
    }

    public void setMultiFeatures(Map<String, Map<String, Object>> multiFeatures) {
        this.multiFeatures = multiFeatures;
    }

    public String getTraceId() {
        return traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public Map<String, Map<String, Object>> getTotalFeatures() {
        if (totalFeatures == null) {
            if (multiFeatures != null) {
                // 初始化究极 totalFeatures，先按照多候选集的 key 把公共特征放进去，再把具体每个候选集的特征放进去
                // 如果公共特征与候选集里的特征有重复，以候选集里面的为准
                totalFeatures = new HashMap<>(multiFeatures.size());
                multiFeatures.keySet().forEach(key -> {
                    if (features != null) {
                        totalFeatures.put(key, new HashMap<>(features));
                    } else {
                        totalFeatures.put(key, new HashMap<>());
                    }
                });
                totalFeatures.forEach((key, value) -> value.putAll(multiFeatures.get(key)));
            } else {
                totalFeatures = new HashMap<>(1);
                totalFeatures.put(null, features);
            }
        }
        return totalFeatures;
    }
}
